<%--
  Created by IntelliJ IDEA.
  User: corcutt
  Date: Mar 15, 2009
  Time: 3:56:03 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Edit Event</title></head>
<script LANGUAGE="JavaScript">
    <!--
    // Nannette Thacker http://www.shiningstar.net
    function confirmDeletePosition()
    {
        var agree = confirm("Are you sure you wish to remove the position from the event?");
        if (agree)
            return true;
        else
            return false;
    }
    // -->
</script>
<body>
<%@ include file="header.jspf" %>
<form:form modelAttribute="event">
<h3>Edit Your Event Information:</h3>
<table width="100%">
    <tr>
        <td>Event Name:</td>
        <td>
            <form:input path="name" autocomplete="false"/> <!-- email parameter mapped somewhere.. ? -->
            <form:errors path="name" cssStyle="color: red"/>
        </td>
    </tr>
    <tr>
        <td>Event Description:</td>
        <td>
            <form:input path="description" autocomplete="false"/>
            <form:errors path="description" cssStyle="color: red"/>
        </td>
    </tr>
    <tr>
        <td>Event Location:</td>
        <td>
            <form:input path="location" autocomplete="false"/>
        </td>
    </tr>
    <tr>
        <td>Event Start Date and Time (yyyy-mm-dd hh:mm:ss):</td>
        <td>
            <form:input path="startDateAndTime" autocomplete="false"/>
            <form:errors path="startDateAndTime" cssStyle="color: red"/>
        </td>
    </tr>
    <tr>
        <td>Event End Date and Time (yyyy-mm-dd hh:mm:ss):</td>
        <td>
            <form:input path="endDateAndTime" autocomplete="false"/>
            <form:errors path="endDateAndTime" cssStyle="color: red"/>
        </td>
    </tr>

    <form:hidden path="id"/>
    <tr>
        <td colspan="2" style="text-align:center"><input type="submit" value="Update"></td>
        </form:form>
    </tr>
</table>


<table border="1" width="100%">
    <tr>
        <td colspan="8">Positions for Event: ${event.name} </td>
        <td colspan="1">
            <form method="GET" action="<c:url value="createPosition"/>" name="createPosition">
                <input type="hidden" name="eventID" value="${event.id}"/>

                <p class="submit"><input type="submit" value="Add Position"/></p>
            </form>
        </td>
    </tr>
    <tr>
        <%@ include file="positionsListTableHeader.jspf" %>
        <td BGCOLOR="limegreen"></td>
    </tr>

    <c:if test="${empty event.eventPositions}">
        <br>

        <h3><strong>All positions are currently filled.</strong></h3>
    </c:if>
    <c:if test="${not empty event.eventPositions}">

        <c:forEach var="position" items="${event.eventPositions}">
            <tr>
                <%@ include file="positionsListTable.jspf" %>
                <td valign="top">
                    <table>
                        <tr>
                            <td>
                                <form method="GET" action="<c:url value="editPosition"/>" name="editPosition">
                                    <input type="hidden" name="eventID" value="${event.id}"/>
                                    <input type="hidden" name="positionID" value="${position.id}"/>

                                    <p class="submit"><input type="submit" value="Edit Position"/></p>
                                </form>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                <!-- only allow for deleting of a position if there are no volunteers -->
                                <form method="GET" action="<c:url value="deletePosition"/>" name="deletePosition">
                                    <input type="hidden" name="eventID" value="${event.id}"/>
                                    <input type="hidden" name="positionID" value="${position.id}"/>
                                    <c:choose>
                                        <c:when test="${!empty position.volunteers}">
                                            <p class="submit"><input disabled="true" type="submit"
                                                                     value="Delete Position"/></p>
                                        </c:when>
                                        <c:otherwise>
                                            <p class="submit"><input type="submit" value="Delete Position"
                                                                     onClick="return confirmDeletePosition()"/></p>
                                        </c:otherwise>
                                    </c:choose>
                                </form>
                            </td>
                        </tr>
                    </table>
                </td>

            </tr>
        </c:forEach>
    </c:if>
</table>
<%@ include file="footer.jspf" %>

</body>
</html>